﻿using System;
using System.ServiceModel;
using Framework.Remoting.Conventions;
using Xunit;

namespace Framework.Tests.Wcf.Conventions
{
    public class BindingFactoryTest
    {

        private readonly IBindingFactory target = new BindingFactory();
        private void Test_BindingType_Base<TBinding>(string bindingType)
        {
            var actual = target.Create(bindingType);
            Assert.True(actual is TBinding);
            Assert.Equal(new TimeSpan(Int32.MaxValue), actual.CloseTimeout);
            Assert.Equal(new TimeSpan(Int32.MaxValue), actual.OpenTimeout);
            Assert.Equal(new TimeSpan(Int32.MaxValue), actual.ReceiveTimeout);
            Assert.Equal(new TimeSpan(Int32.MaxValue), actual.SendTimeout);
        }

        [Fact]
        public void When_BindingType_is_netTcpBinding_Then_Binding_is_NetTcpBinding()
        {
            Test_BindingType_Base<NetTcpBinding>("netTcpBinding");
        }

        [Fact]
        public void When_BindingType_is_basicHttpBinding_Then_Binding_is_BasicHttpBinding()
        {
            Test_BindingType_Base<BasicHttpBinding>("basicHttpBinding");
        }

        [Fact]
        public void When_BindingType_not_exist_Then_BindingNotFoundException_Expected()
        {
            var e = Assert.Throws<BindingNotFoundException>(() => target.Create("pouet"));
            Assert.Equal("Binding : pouet does not exist", e.Message);
        }
    }
}